package jjn.effective_java.chapter6.item34;

/**
 * @author Jiang Jining
 * @since 2023-04-26 23:58
 */
public enum PayType {
    
    WEEKDAY {
        @Override
        int overtimePay(int minsWorked, int payRate) {
            return minsWorked <= MINS_PER_SHIFT ? 0 : (minsWorked - MINS_PER_SHIFT) * payRate / 2;
        }
    },
    
    WEEKEND {
        @Override
        int overtimePay(int minsWorked, int payRate) {
            return minsWorked * payRate / 2;
        }
    };
    private static final int MINS_PER_SHIFT = 60 * 8;
    
    abstract int overtimePay(int minsWorked, int payRate);
    
    int pay(int minutesWorked, int payRate) {
        int basePay = minutesWorked * payRate;
        return basePay + overtimePay(minutesWorked, minutesWorked);
    }
}
